
mixin list(emp)
   if (emp)
      li
         span
            a(href='#')= emp.name
            
         ul
            - each p in emp.subnodes
               if(0 < p.subnodes.length) 
                  +list(p)
               else
                  li
                     span
                        a(href='#')= p.name


extend ./_layout

block script
   script.
      $(document).ready(function(){
         //$('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
         $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Expand this branch').addClass('icon-plus-sign').removeClass('icon-minus-sign');
         $('.tree li.parent_li > span').on('click', function (e) {
           var children = $(this).parent('li.parent_li').find(' > ul > li');
           if (children.is(":visible")) {
               children.hide('slow');
               $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
           } else {
               children.show('slow');
               $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
           }
           e.stopPropagation();
         });         
      });

      
      
block content
   div
      form(action='/emp/tree/' + rootnode._id, method='post')
         input(name = 'name', placeholder = 'Name')
         select(name = 'parent')
            - each emp in employees
               option(value = emp._id)= emp.name
         
         input(type="submit", value = 'submit')

   div.tree
      ul
         +list(root)
   
     